<!DOCTYPE html>
<html>
<head>
	<title>Cool Quiz App</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1" />
 	<link rel="stylesheet" href="jquery/jquery.mobile-1.2.0.min.css" />
 	<script src="jquery/jquery-1.8.2.min.js"></script>
	<script src="jquery/jquery.mobile-1.2.0.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="cordova-2.1.0.js"></script>


<script type="text/javascript">

function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {
	// back button on homepage exits app
	document.addEventListener("backbutton", function(e){
		console.log("active page: " + $.mobile.activePage.attr('id'));
	    if($.mobile.activePage.attr('id') == 'index'){
	        e.preventDefault();
	        navigator.app.exitApp();
	    }
	    else {
	        navigator.app.backHistory()
	    }
	}, false);
}

function showAnswer(questionId){
	hideAnswer();
	// images to be inserted for correct and wrong answers
	correctdiv = '<span class="correct"><img src="images/correct.png" alt="correct" style="margin-left:5px"/></span>';
	incorrectdiv = '<span class="incorrect"><img src="images/incorrect.png" alt="wrong" style="margin-left:5px" /></span>';
	correct = 1;
	$('#'+questionId+' .option').each(function (index, domEle) {
		if ((($(domEle).find('input').val() == 1) && $(domEle).find('input').is(':checked'))
		|| (($(domEle).find('input').val() == 0) && !$(domEle).find('input').is(':checked'))){
			$(domEle).find('.ui-icon').before(correctdiv);
			}else{
				$(domEle).find('.ui-icon').before(incorrectdiv);
				correct = 0;
			};
		// reveal reason block	
		$('.reason').show("slide");
	})
	// currently uses local storage which is not permanent
	// would be better to save answers to database
	window.localStorage.setItem(questionId, correct);
	updateResults();
}

function hideAnswer(){
	$('.correct').remove();
	$('.incorrect').remove();
	$('.reason').hide();
}

function updateResults(){
	 var sum = parseInt(window.localStorage.getItem("q1_1")) + parseInt(window.localStorage.getItem("q1_2")) + parseInt(window.localStorage.getItem("q1_3"));
	 $('#q1_sum').html(sum);
}
</script>
<style>
.reason
{
background-image: url('images/information.png');
background-repeat: no-repeat;
padding-left: 55px;  
min-height:48px;
display: block; 
}

.ui-header, .ui-title, .ui-footer{  
    margin-right: 0 !important;
    margin-left: 0 !important;
}
</style>
</head>
<body onload="onLoad()">

<div data-role="page" id="index">

	<div data-role="header">
		<h1>Topics</h1>
	</div><!-- /header -->

	<div data-role="content">
		<h1>Select a topic</h1>
		<ul data-role="listview">
			<li><a href="#quiz1">Quiz 1: XML</a></li>
			<li><a href="#quiz2">Quiz 2: JavaScript</a></li>
			<li><a href="#quiz3">Quiz 3: Servlets</a></li>
			<li><a href="#quiz4">Quiz 4: JSP</a></li>
		</ul>
		<br/>
		<p><a href="#results" data-role="button">See results</a></p>
		
	</div><!-- /content -->

	<div data-role="footer">
		<h4>Cool Quiz App</h4>
	</div><!-- /footer -->
</div><!-- /page -->


<div data-role="page" id="quiz1">

	<div data-role="header">
		<h1>Quiz 1: XML</h1>
	</div><!-- /header -->

	<div data-role="content">
	<p>This quiz is about XML. This page could have a more detailed description or even show which questions have been answered correctly so far.</p>
	<form action="#answer1" method="post" id="q1_1">
		<div data-role="controlgroup" data-type="horizontal" >
			<a href="#quiz1q1" data-role="button">next</a>
		</div>
		</form>
	</div><!-- /content -->

	<div data-role="footer">
		<h4><a href="#index">Home</a></h4>
	</div><!-- /footer -->
</div><!-- /page -->

<!-- quiz1q1 = Quiz 1, Question 1 -->
<div data-role="page" id="quiz1q1">

	<div data-role="header">
		<h1>Quiz 1: XML  (1/3)</h1>
	</div><!-- /header -->

	<div data-role="content">
	<form action="#answer1" method="post" id="q1_1">
		<fieldset data-role="controlgroup">
			<legend>What does XML stand for?</legend>
			<!-- q1_1_1 = Quiz 1, Question 1, Option 1 -->
			<span class="option"><input type="radio" name="q1_1" id="q1_1_1" value="0" ><label for="q1_1_1">Expandable Mark-up Language</label></span>
			<span class="option"><input type="radio" name="q1_1" id="q1_1_2" value="1"><label for="q1_1_2">Extensible Mark-up Language</label></span>
			<span class="option"><input type="radio" name="q1_1" id="q1_1_3" value="0"><label for="q1_1_3">Extreme Mark-up Language</label></span>
		</fieldset>
		<div class="reason" style="display:none">
			<p>XML stands for Extensible Mark-up Language. The other answers are made up.</p>
		</div>
		<div data-role="controlgroup" data-type="horizontal" >
			<a data-role="button" onclick="showAnswer('q1_1')">check answer</a>
			<a href="#quiz1q2" data-role="button" onclick="hideAnswer()">next</a>
		</div>
		</form>
	</div><!-- /content -->

	<div data-role="footer">
		<h4><a href="#index">Home</a></h4>
	</div><!-- /footer -->
</div><!-- /page -->


<div data-role="page" id="quiz1q2">

	<div data-role="header">
		<h1>Quiz 1: XML  (2/3)</h1>
	</div><!-- /header -->

	<div data-role="content">
	<form action="#answer1" method="post" id="q1_2">
		<fieldset data-role="controlgroup">
			<legend>What does SGML stand for?</legend>
			<span class="option"><input type="radio" name="q1_2" id="q1_2_1" value="1" ><label for="q1_2_1">Standard Generalized Mark-up Language</label></span>
			<span class="option"><input type="radio" name="q1_2" id="q1_2_2" value="0"><label for="q1_2_2">Super Guper Mark-up Language</label></span>
			<span class="option"><input type="radio" name="q1_2" id="q1_2_3" value="0"><label for="q1_2_3">Silly General Mark-up Language</label></span>
		</fieldset>
		<div class="reason" style="display:none">
			<p>SGML stands for Standard Generalized Mark-up Language. The other answers are made up.</p>
		</div>
		<div data-role="controlgroup" data-type="horizontal" >
			<a data-role="button" onclick="showAnswer('q1_2')">check answer</a>
			<a href="#quiz1q3" data-role="button" onclick="hideAnswer()">next</a>
		</div>
		</form>
	</div><!-- /content -->

	<div data-role="footer">
		<h4><a href="#index">Home</a></h4>
	</div><!-- /footer -->
</div><!-- /page -->

<div data-role="page" id="quiz1q3">

	<div data-role="header">
		<h1>Quiz 1: XML  (3/3)</h1>
	</div><!-- /header -->

	<div data-role="content">
	<form action="#answer1" method="post" id="q1_3">
		<fieldset data-role="controlgroup">
			<legend>Which of the following tags are correct XML?</legend>
			<span class="option"><input type="checkbox" name="q1_3" id="q1_3_1" value="1" ><label for="q1_3_1">&lt;br /&gt;</label></span>
			<span class="option"><input type="checkbox" name="q1_3" id="q1_3_2" value="1"><label for="q1_3_2">&lt;name&gt;me&lt;/name&gt;</label></span>
			<span class="option"><input type="checkbox" name="q1_3" id="q1_3_3" value="1"><label for="q1_3_3">&lt;name&gt;&lt;nick&gt;me&lt;/nick&gt;&lt;/name&gt;</label></span>
			<span class="option"><input type="checkbox" name="q1_3" id="q1_3_4" value="1"><label for="q1_3_4">&lt;br /&gt;&lt;br /&gt;</label></span>
		</fieldset>
		<div class="reason" style="display:none">
			<p>All tags must be closed and nested properly.</p>
		</div>
		<div data-role="controlgroup" data-type="horizontal" >
			<a data-role="button" onclick="showAnswer('q1_3')">check answer</a>
			<a href="#index" data-role="button" onclick="hideAnswer()">next</a>
		</div>
		</form>
	</div><!-- /content -->

	<div data-role="footer">
		<h4><a href="#index">Home</a></h4>
	</div><!-- /footer -->
</div><!-- /page -->


<div data-role="page" id="results">

	<div data-role="header">
		<h1>Results</h1>
	</div><!-- /header -->

	<div data-role="content">
		<h1>Results</h1>
		<ul data-role="listview">
			<li>Quiz 1: XML (<span id="q1_sum"></span>/3 questions correct)</li>
			<li>Quiz 2: JavaScript (not attempted)</li>
			<li>Quiz 3: Servlets (not attempted)</li>
			<li>Quiz 4: JSP (not attempted)</li>
		</ul>
	</div><!-- /content -->

	<div data-role="footer">
		<h4><a href="#index">Home</a></h4>
	</div><!-- /footer -->
</div><!-- /page -->



</body>
</html>